home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 3 / CU Amiga Magazine's Super CD-ROM 03 (1996)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1996-09].iso / graphics / yafg / julia3 / julia3.c < prev   
C/C++ Source or Header  |  1996-05-23  |  3KB  |  160 lines

  1. /***********************************/
  2. /*  Yet Another Fractal Generator  */
  3. /*                                 */
  4. /*        Juliaset for z³+c        */
  5. /*       (C) 1996 by MaCheFi       */
  6. /*       szczerba@us.edu.pl        */
  7. /*        zfjmgr@us.edu.pl         */
  8. /***********************************/
  9.  
  10. #include <intuition/intuition.h>
  11. #include <proto/exec.h>
  12. #include <proto/graphics.h>
  13. #include <proto/intuition.h>
  14.  
  15. #include <functions.h>
  16. #include <graphics/modeid.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19.  
  20. #define WIDTH 512
  21. #define HEIGHT 512
  22. #define DEPTH 8
  23. #define COLORS 256
  24.  
  25. #define dx0 (x0_max-x0_min)/WIDTH
  26. #define dy0 (y0_max-y0_min)/HEIGHT
  27.  
  28. struct Screen *scr;
  29. struct IntuitionBase *IntuitionBase;
  30. struct GfxBase *GfxBase;
  31.  
  32. ULONG modeid=DEFAULT_MONITOR_ID | HIRESLACE_KEY;
  33.  
  34. void stupid(void)
  35. {
  36.     if (scr) CloseScreen(scr);
  37.     if (GfxBase) CloseLibrary((struct Library *)GfxBase);
  38.     if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  39.     exit(0);
  40. }
  41.  
  42. void OpenAllLibraries(void)
  43. {
  44.     IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",37);
  45.     if (!IntuitionBase)
  46.     {
  47.         printf("You need intuition.library v.37+!!!\n");
  48.         stupid();
  49.     }
  50.     GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",37);
  51.     if (!GfxBase)
  52.     {
  53.         printf("You need graphics.library v.37+!!!\n");
  54.         stupid();
  55.     }
  56. }
  57.  
  58. void gimmecolors(void)
  59. {
  60.     ULONG i;
  61.     for(i=0;i<COLORS;i++)
  62.     {
  63.         SetRGB32(&scr->ViewPort, i,(ULONG)(((float)i/0xff)*0xffffffff), (ULONG)(((float)i/0xff)*0xffffffff), (ULONG)(((float)i/0xff)*0xffffffff));
  64.     }
  65. }
  66.  
  67. void main(int argc,char *argv[])
  68. {
  69.     int color;
  70.     long int i,j;
  71.     float x0,y0;
  72.     float x,y;
  73.     float tempx;
  74.     float a,b;
  75.     float x0_min,x0_max,y0_min,y0_max;
  76.     long int N;
  77.     long int L;
  78.     long int HOWMANY;
  79.  
  80.     if(argc!=8)
  81.     {
  82.         printf("Arguments: x_min x_max y_min y_max a b N\n");
  83.         exit(0);
  84.     }
  85.  
  86.     x0_min = atof(argv[1]);
  87.     x0_max = atof(argv[2]);
  88.     y0_min = atof(argv[3]);
  89.     y0_max = atof(argv[4]);
  90.     a      = atof(argv[5]);
  91.     b      = atof(argv[6]);
  92.     N      = atol(argv[7]);
  93.  
  94.     OpenAllLibraries();
  95.  
  96.     if(ModeNotAvailable(modeid))
  97.         stupid();
  98.  
  99.     if(!(scr=OpenScreenTags(0,
  100.     SA_Width, WIDTH,
  101.     SA_Height, HEIGHT,
  102.     SA_Depth, 8,
  103.     SA_Type, PUBLICSCREEN,
  104.     SA_DisplayID, modeid,
  105.     TAG_DONE))) stupid();
  106.  
  107.     gimmecolors();
  108.  
  109.     SetRast(&scr->RastPort,255);
  110.  
  111.     y0=y0_max;
  112.     for(j=0;j<HEIGHT;j++)
  113.     {
  114.         if(scr->MouseX<2 && scr->MouseY<2)
  115.         {
  116.             stupid();
  117.             break;
  118.         }
  119.         x0=x0_min;
  120.         for(i=0;i<WIDTH;i++)
  121.         {
  122.             x=x0;
  123.             y=y0;
  124.  
  125.             if( (x0 * x0 + y0 * y0) >= 2)
  126.             {
  127.                 HOWMANY=0;
  128.                 goto skip;
  129.             }
  130.  
  131.             HOWMANY=0;
  132.             for(L=1;L<=N;L++)
  133.             {
  134.                 tempx = x * x * x - 3 * x * y * y + a;
  135.                 y = 3 * x * x * y - y * y * y + b;
  136.                 x=tempx;
  137.             if( (x * x + y * y) < 2) HOWMANY++;
  138.                 else break;
  139.             }
  140.             skip:
  141.             color = (int)( (COLORS-1)*(1.0 - (float)HOWMANY/N) );
  142.             SetAPen(&scr->RastPort,color);
  143.             WritePixel(&scr->RastPort,i,j);
  144.             x0+=dx0;
  145.         }
  146.         y0-=dy0;
  147.     }
  148.  
  149.     for(;;)
  150.     {
  151.         if(scr->MouseX<2 && scr->MouseY<2)
  152.         {
  153.             stupid();
  154.             break;
  155.         }
  156.         Delay(50);
  157.         printf("Where is top left screen corner...?\n");
  158.     }
  159. }
  160.